package com.yugu.park.business.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageInfo;
import com.yugu.enums.BusinessType;
import com.yugu.park.annotation.Log;
import com.yugu.park.business.entity.CardInfo;
import com.yugu.park.business.entity.MemberInfo;
import com.yugu.park.business.service.CardInfoService;
import com.yugu.util.ResponseUtil;
import com.yugu.util.SearchPage;
import com.yugu.util.SysQueryParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @author Noble-Six
 * @date 2024/4/25
 */
@RestController
@Api(tags = "年卡信息")
@RequestMapping("/business/cardInfo")
public class CardInfoController {

    @Resource
    private CardInfoService cardInfoService;

    @ApiOperation(value = "新增修改年卡信息")
    @PostMapping("/addOrUpdate")
    @Log(title ="新增修改年卡信息" ,businessType = BusinessType.UPDATE)
    public ResponseUtil.Result<Boolean> addOrUpdate(@RequestBody CardInfo info){
        cardInfoService.addOrUpdate(info);
        return ResponseUtil.addSuccess(true);
    }
    @ApiOperation(value="分页查询", notes="分页查询")
    @PostMapping(value = "/page")
    public ResponseUtil.Result<PageInfo<CardInfo>> page (@RequestBody SearchPage<SysQueryParam> search){
        PageInfo<CardInfo> page = cardInfoService.page(search);
        return ResponseUtil.addSuccess(page);
    }
    @ApiOperation(value="批量删除", notes="批量删除")
    @DeleteMapping(value="/{id}")
    @Log(title ="删除年卡信息" ,businessType = BusinessType.DELETE)
    public ResponseUtil.Result<Boolean> delete(@PathVariable("id") String id){
        cardInfoService.removeIds(Arrays.asList(id.split(",")));
        return ResponseUtil.addSuccess(true);
    }
    @ApiOperation(value = "获取所有年卡")
    @GetMapping("/getAll")
    public ResponseUtil.Result<List<CardInfo>> getAll(){
        List<CardInfo> list = cardInfoService.list();
        return ResponseUtil.addSuccess(list);
    }

}
